<template>
  <div class="comment-post">
    <!-- 添加trim修饰 -->
    <van-field class="post-field" v-model.trim="inputComment" rows="2" autosize type="textarea" maxlength="50"
      placeholder="请输入留言" show-word-limit />
    <!-- 添加disabled控制禁用 -->
    <van-button class="post-btn" type="" @click="onAddComment" :disabled="!inputComment.length">发布</van-button>
  </div>
</template>

<script>
import { addComment } from '@/api/comment'
export default {
  name: 'PostComment',
  data () {
    return {
      inputComment: ''
    }
  },
  inject: {
    // 文章id
    artId: {
      type: [Number, String, Object],
      default: null
    }
  },
  props: {
    // 评论目表id
    target: {
      type: [Number, String, Object],
      required: true
    }

  },
  methods: {
    // 点击发布按钮
    async onAddComment () {
      // const toast = this.$toast.loading({
      //   duration: 0, // 持续展示 toast
      //   message: '加载中...',
      //   forbidClick: true
      // })
      try {
        const { data: res } = await addComment({
          target: this.target + '',
          content: this.inputComment,
          art_id: this.artId ? (this.artId + '') : this.artId
        })
        console.log(res)
        const result = res.data
        console.log(result)
        // result.is_link.new_obj.is_liking = false
        this.$emit('onpost-success', result)
      } catch (err) {
      }
    }
  },
  computed: {},
  watch: {},
  filters: {},
  components: {},
  created () { },
  mounted () { }
}
</script>

<style scoped lang='less'>
.comment-post {
  display: flex;
  align-items: center;
  padding: 32px 0 32px 32px;
  .post-field {
    background-color: #f5f7f9;
  }
  .post-btn {
    width: 150px;
    border: none;
    padding: 0;
    color: #6ba3d8;
    background-color: #fff;
    &::before {
      display: none;
    }
  }
}
</style>
